<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateItemRequestsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('item_requests', function($table){
			$table->increments('pk');
			$table->integer('requested_by_fk')->unsigned();
			$table->integer('approved_by_fk')->unsigned();
			$table->integer('request_status_fk')->unsigned();
			$table->date('approval_date');
			$table->timestamps();
		});

		Schema::table('item_requests', function($table){
			$table->foreign('requested_by_fk')->references('pk')->on('users');
			/*$table->foreign('approved_by_fk')->references('pk')->on('users');*/
			$table->foreign('request_status_fk')->references('pk')->on('item_request_status');
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('item_requests', function($table){
			$table->dropForeign('item_requests_requested_by_fk_foreign');
			/*$table->dropForeign('item_requests_approved_by_fk_foreign');*/
			$table->dropForeign('item_requests_request_status_fk_foreign');
		});
		echo "item_requests table relationships removed\n";
		Schema::drop('item_requests');
		echo "item_requests table deleted\n";
	}

}
